<% layout('/layouts/default.html', {title: '来文登记表管理', libs: ['dataGrid']}){ %>
<style>
    .camera {
        height: 30px;
        background-color: #ffffff;
        border-color: #1E5EDB;
        color: #1E5EDB;
        margin-top: 8px;
    }

</style>
<div class="main-content">
    <div class="box box-main">
        <div class="box-body">
            <#form:form id="inputForm"  action="${ctx}/sd/docDeliverWaitTake/takefile"
            method="post" >
            <div class="row"  style="margin-bottom: 88px;margin-top: 2%">
                <div class="col-xs-3">
                    <div class="form-group">
                        <label class="control-label">${text('送文单位')}：</label>
                        <div class="control-inline">
                            <#form:treeselect id="testOffice" title="机构选择"
                            path="officeCode" labelPath="testOffice.officeName"
                            url="${ctx}/sd/docDeliverRecord/treeDataSend" class="" canSelectRoot="false"
                            allowClear="true" checkbox="true"
                            callbackFuncName="selectfile"
                            />
                        </div>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="form-group">
                        <label class="control-label">${text('姓名')}：</label>
                        <div class="control-inline">
                            <#form:input id="userName" path="userName" onchange="chan()" title="姓名" value="${userName}"
                            class="form-control required" />
                            <#form:input id="userCode" path="userCode" title="保密处人编码" value="${userCode}"
                            class="form-control"  type="hidden"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="form-group">
                        <label class="control-label">${text('警号')}：</label>
                        <div class="control-inline">
                            <#form:input id="police" title="保密处人警号" readOnly="true"  path="police" onchange="jh()" value="${police}"
                            class="form-control required" />
                        </div>
                    </div>
                </div>
                <div class="col-xs-5" style="position: absolute;right: -250px;top: 20px;">
                    <div class="form-group">
                        <label class="control-label col-sm-2">
                        </label>
                        <div class="col-sm-8">

                            <img  id="showImg" style="width: 150px;border-radius: 50%;cursor: pointer" class="img-responsive"  src="${ctxStatic}/camera.jpg" class="img-responsive" title="领文人拍照" onclick="collectPicture()">
                        </div>
                    </div>
                </div>


                <#form:input id="face" title="人脸"
                class="form-control required" path="face" type="hidden" />
                 <div class="hide">

                        <button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i>
                            ${text('保 存')}
                        </button>&nbsp;
                        <button type="button" class="btn btn-sm btn-default" id="btnCancel"
                                onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}
                        </button>
                </div>
            </div>

        </div>


    </div>

</div>

</#form:form>

<table id="dataGrid"></table>
<form id="searchForm" action="${ctx}/sd/docDeliverWaitTake/selectFileByUnits" method="post">

</form>
<% } %>
<script>
    window.onload=function () {
    $("#face").val(0);
    }
    function chan() {
        $("#pace").css("display", "block")
        $("#face").val("");
    document.getElementById("police").removeAttribute("readOnly")
        document.getElementById("police").value=""
        $("#userCode").val("");
    }

    function jh() {
        $("#pace").css("display", "block")
        $("#face").val("");
        $("#userCode").val("");
    }

    function selectfile(id, act, index, layero, nodes) {
        $("#dataGrid").html("")
        var arr = new Array();
        if (id == 'testOffice' && (act == 'ok' || act == 'clear')) {
            // log(win);    // 选择框内容的window对象
            // log(act);    // 回调活动事件（ok、clear、cancel）
            // log(index);  // layer的index
            // log(layero); // layer实例对象
            // log(selectData);  // 选择的节点数据
            console.log(nodes)
            var win = layero.iframeWindow();
            for (var i = 0; i < nodes.length; i++) {

                arr.push(nodes[i].id)
            }
            console.log(arr)
            $.ajax({
                type: "GET",
                url: "${ctx}/sd/docDeliverWaitTake/selectFileByUnits?untis=" + arr,
                success: function (data) {
                    if (data.result == Global.FALSE) {
                        document.getElementById("testOfficeName").value = ""
                        document.getElementById("testOfficeCode").value = ""
                        js.layer.msg("没有文件可送", {icon: 5})

                    } else {
                        js.layer.msg("核对文件", {icon: 1})
                        console.log(data)

                        var info = data.data;
                        for (var i = 0; i < info.length; i++) {
                            $('#dataGrid').jqGrid('addRow', {
                                position: 'last',
                                addRowParams: {keys: true, focusField: true},
                                initdata: {
                                    idd: info[i].docId,
                                    fileTitle: info[i].docRecv.docTitle,
                                    takeUnitName: info[i].office.officeName,

                                }
                            });
                        }
                    }
                }
            })

        }
    }
    function collectPicture() {
        js.layer.open({
            type: 2,
            area: [(js.layer.window.outerWidth - 350) + 'px', (js.layer.window.outerHeight - 200) + 'px'],
            title: '${text("拍照")}',
            resize: false,
            scrollbar: true,
            maxmin: true,
            content: '${ctx}/sd/collectPicture/form',
            success: function (layero, index) {

            },
            btn: ['<i class="fa fa-check"></i> ${text("上传")}',
                '<i class="fa fa-remove"></i> ${text("关闭")}'],
            btn1: function (index, layero) {
                var win = layero.iframeWindow();
                if (typeof (win.getFile()) == "undefined") {
                    js.layer.msg('请先拍照再提交!', {icon: 5});
                    return false;
                }
                console.log(typeof (win.getFile()));
                var formData = new FormData;
                formData.append("file", win.getFile());
                $.ajax({
                    type: "POST",
                    url: "${ctx}/sd/collectPicture/uploadFile",
                    data: formData,
                    contentType: false,
                    processData: false,
                    success: function (data) {
                        if (data.result === Global.TRUE) {
                            js.layer.msg(data.message, {icon: 1});
                            js.layer.close(index);
                            $('#face').val(data.data);
                            facepath=win.getUrl();
                              $("#showImg").attr("src",facepath)

                           // $("#showImg").attr("onclick","rese()");
                            return true;
                        } else {
                            js.layer.msg(data.message, {icon: 5});
                            return false;
                        }

                    }
                })
                return false;

            }


        });
    }
    /*function rese(){
        js.layer.confirm("<div> <img src="+facepath+"  style='height: 300px;'> </div>",{
            title : "预览照片",
            skin : "my-skin",
            btn : [ '重拍', '取消' ],
            yes:function () {
                collectPicture();
            }

        })
    }
*/
    // 初始化DataGrid对象
    $('#dataGrid').dataGrid({
        // 查询数据表单
        searchForm: $('#searchForm'),
        showRownum: false,
        // 设置数据表格列
        columnModel: [
            {header: '文件编号', name: 'idd'},
            {header: '文件标题', name: 'fileTitle'},
            {header: '收文单位', name: 'takeUnitName'},

        ],
        // 加载成功后执行事件
        ajaxSuccess: function (data) {

        }
    });

</script>